package com.demo.controller;

import com.demo.bean.Article;
import com.demo.bean.Student;
import com.demo.common.Result;
import com.demo.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: lixiaodong
 * @Description:  restfull风格测试
 * @Date: 2022/9/15 15:45
 * @Parms: 
 * @ReturnType: 
 */
@Api(tags = "restfull风格测试")
@Slf4j
@RestController
public class ArticleController  extends BaseController{
	@Autowired
	ArticleService articleService;

	@ApiOperation(value = "PathVariable用法", notes = "PathVariable用法")
	@GetMapping("/article/{id}")
	public Result findById(@PathVariable(value = "id") Integer id){
		return articleService.findById(id);
	}

	@ApiOperation(value = "PathVariable用法2", notes = "PathVariable用法2")
	@GetMapping("/findByTitle/{title}")
	public Result findByTitle(@PathVariable(value = "title") String title){
		return articleService.findByTitle(title);
	}
	@ApiOperation(value = "PathVariable用法3", notes = "PathVariable用法3")
	@GetMapping("/articlePage/{pageId}/{pageSize}")
	public Result findPage(@PathVariable(value = "pageId") Integer pageId,
								   @PathVariable(value = "pageSize") Integer pageSize){
		return articleService.findPage(pageId,pageSize);
	}
	@ApiOperation(value = "PathVariable用法4", notes = "PathVariable用法4")
	@DeleteMapping("/article/{ids}")
	public Result delete(@PathVariable("ids") List<Long> ids ){
		return articleService.delete(ids);
	}
	@ApiOperation(value = "RequestBody用法", notes = "RequestBody用法")
	@PostMapping("/article")
	public Result insert(@RequestBody List<Article> articleList ){
		return articleService.insert(articleList);
	}
	@ApiOperation(value = "RequestBody用法2", notes = "RequestBody用法2")
	@PutMapping("/article")
	public Result update(@RequestBody Article article ){
		return articleService.update(article);
	}
	@ApiOperation(value = "RequestBody用法3", notes = "RequestBody用法3")
	@PostMapping("/getFromBody")
	public void getFromBody( @RequestBody Student student){
		log.info("student:{}",student.toString());
	}
}
